//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "Switzerland.h"
using namespace Cephei::QL::Times::Calendars;
#include <gen/QL/Times/Period.h>
#include <gen/QL/Times/Calendar.h>
using namespace Cephei::QL::Times;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Times::Calendars::CSwitzerland::CSwitzerland () : CCalendar(CSwitzerland::typeid)
{
    try
    {
#ifdef HANDLE
        _phSwitzerland = NULL;
#endif
        _ppSwitzerland = new boost::shared_ptr<QuantLib::Switzerland> (new QuantLib::Switzerland ( ));
        SetCalendar (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppSwitzerland));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Times::Calendars::CSwitzerland::CSwitzerland (boost::shared_ptr<QuantLib::Switzerland>& childNative, Object^ owner) : CCalendar(CSwitzerland::typeid)
{
#ifdef HANDLE
	_phSwitzerland = NULL;
#endif
	_ppSwitzerland = &childNative;
    _ppCalendar = new boost::shared_ptr<QuantLib::Calendar> (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppSwitzerland));
}
Cephei::QL::Times::Calendars::CSwitzerland::CSwitzerland (QuantLib::Switzerland& childNative, Object^ owner) : CCalendar(CSwitzerland::typeid)
{
#ifdef HANDLE
	_phSwitzerland = NULL;
#endif
	_ppSwitzerland = new boost::shared_ptr<QuantLib::Switzerland> (&childNative);
    _ppCalendar = new boost::shared_ptr<QuantLib::Calendar> (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppSwitzerland));
    _SwitzerlandOwner = owner;
    _CalendarOwner = owner;
}

Cephei::QL::Times::Calendars::CSwitzerland::CSwitzerland (CSwitzerland^ copy) : CCalendar(CSwitzerland::typeid)
{
#ifdef HANDLE
	_phSwitzerland = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppSwitzerland = new boost::shared_ptr<QuantLib::Switzerland> (copy->GetShared());
        _ppCalendar = new boost::shared_ptr<QuantLib::Calendar> (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppSwitzerland));
    }
}
Cephei::QL::Times::Calendars::CSwitzerland::CSwitzerland (PLATFORM::Type^ t) : CCalendar(CSwitzerland::typeid)
{
#ifdef HANDLE
	_phSwitzerland = NULL;
#endif
	if (!t->IsSubclassOf(CSwitzerland::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Times::Calendars::CSwitzerland::CSwitzerland (QuantLib::Handle<QuantLib::Switzerland>& childNative, Object^ owner)  : CCalendar(CSwitzerland::typeid)
{
	_phSwitzerland = &childNative;
	_ppSwitzerland = &static_cast<boost::shared_ptr<QuantLib::Switzerland>>(childNative.currentLink());
    _ppCalendar = new boost::shared_ptr<QuantLib::Calendar> (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppSwitzerland));
    _SwitzerlandOwner = owner;
}
Cephei::QL::Times::Calendars::CSwitzerland::CSwitzerland (QuantLib::Handle<QuantLib::Switzerland> childNative)  : CCalendar(CSwitzerland::typeid)
{
	_phSwitzerland = &childNative;
	_ppSwitzerland = &static_cast<boost::shared_ptr<QuantLib::Switzerland>>(childNative.currentLink());
    _ppCalendar = new boost::shared_ptr<QuantLib::Calendar> (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppSwitzerland));
}
#endif
#ifdef STRUCT
Cephei::QL::Times::Calendars::CSwitzerland::CSwitzerland (QuantLib::Switzerland childNative)  : CCalendar(CSwitzerland::typeid)
{
#ifdef HANDLE
	_phSwitzerland = NULL;
#endif
	_ppSwitzerland = new boost::shared_ptr<QuantLib::Switzerland> (new QuantLib::Switzerland (childNative));
    _ppCalendar = new boost::shared_ptr<QuantLib::Calendar> (boost::dynamic_pointer_cast<QuantLib::Calendar> (*_ppSwitzerland));
}
#endif

Cephei::QL::Times::Calendars::CSwitzerland::~CSwitzerland ()
{
    if (_ppSwitzerland != NULL)
    {
	    delete _ppSwitzerland;
        _ppSwitzerland = NULL;
    }
}
Cephei::QL::Times::Calendars::CSwitzerland::!CSwitzerland ()
{
    if (_ppSwitzerland != NULL)
    {
	    delete _ppSwitzerland;
    }
}
QuantLib::Switzerland& Cephei::QL::Times::Calendars::CSwitzerland::GetReference ()
{
    if (_ppSwitzerland == NULL) throw REFNEW NativeNullException ();
	return **_ppSwitzerland;
}
boost::shared_ptr<QuantLib::Switzerland>& Cephei::QL::Times::Calendars::CSwitzerland::GetShared ()
{
    if (_ppSwitzerland == NULL) throw REFNEW NativeNullException ();
	return *_ppSwitzerland;
}
QuantLib::Switzerland* Cephei::QL::Times::Calendars::CSwitzerland::GetPointer ()
{
    if (_ppSwitzerland == NULL) throw REFNEW NativeNullException ();
	return &**_ppSwitzerland;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::Switzerland>& Cephei::QL::Times::Calendars::CSwitzerland::GetHandle ()
{
	if (_phSwitzerland == NULL)
	{
		_phSwitzerland = new Handle<QuantLib::Switzerland> (*_ppSwitzerland);
	}
	return *_phSwitzerland;
}
#endif
bool Cephei::QL::Times::Calendars::CSwitzerland::HasNative () 
{
	return (_ppSwitzerland != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Times::Calendars::ISwitzerland^ Cephei::QL::Times::Calendars::CSwitzerland_Factory::Create ()
{
    return REFNEW CSwitzerland ();
}
